package com.gjy.spring.s6;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-12-20 09:40:01
 */
public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {
    private static final Logger log = LoggerFactory.getLogger(MyBean.class);

    @Override
    public void setBeanName(String name) {
        log.info("当前bean: {}, 名字: {}", this, name);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("当前bean: {}, 容器: {}", this, applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("当前bean初始化操作");
    }

    @Autowired
    public void aaa(ApplicationContext context) {
        log.info("@Autowired  当前bean: {}, 容器: {}", this, context);
    }

    @PostConstruct
    public void init() {
        log.info("@PostConstruct初始化");
    }
}
